const readline = require('readline-sync');
let arr = [{
        name: "zhangsan",
        password: '123',
        money: 500
    },
    {
        password: '456',
        money: 1000,
        name: "lisi",
    }
];

function main() {
    console.log("1. 登录 2. 注册：");
    let opt = readline.question() - 0;
    let user; // 保存登录用户
    switch (opt) {
        case 1: // 登录
            user = login(); // un {}
            break;
        case 2:
            break;
    }
    if (user) { // 成功
        console.log(`欢迎${user.name}`);
        console.log("1. 存 2. 取 3. 查 4. 退：");
        let opt = readline.question() - 0;
        switch (opt) {
            case 1: // 存 
                save(user);
                break;
            case 2:
                break;
            case 3:
                console.log(`卡上余额：${user.money}元`);
                break;
            case 4:
                console.log(886);
                break;
        }
    } else {
        console.log("查无此人");
    }
}
main();
// 登录
function login() {
    console.log("账号：");
    let iptId = readline.question();
    console.log("密码：");
    let iptPwd = readline.question();
    return arr.filter(item => iptId == item.name && iptPwd == item.password)[0];
}
// 存款
function save(user) { // {账号、密码、钱}
    console.log(`请输入存款金额：`);
    let money = readline.question() - 0;
    user.money += money;
    console.log(user);
}